package com.fdb.efp.flow.service.impl;

import com.fdb.efp.flow.service.dao.InstFlowHistoryDao;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.flow.service.domain.InstFlowHistory;
import com.fdb.efp.flow.service.facade.InstFlowHistoryService;
import com.fdb.efp.flow.service.vo.InstFlowHistoryVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 * 
 * 
 * @author Cytus_
 * @since 2018年5月8日 下午8:11:16
 * @version 1.0
 *
 */
@Service("instFlowHistoryService")
public class InstFlowHistoryServiceImpl implements InstFlowHistoryService, FrameworkService {
	
	
	private static Logger logger = LoggerFactory.getLogger(InstFlowHistoryServiceImpl.class);
	
	
	@Autowired
	private InstFlowHistoryDao instFlowHistoryDao;


	@Override
	public int insertInstFlowHistory(InstFlowHistoryVO instFlowHistoryVO) {
		logger.debug("新增数据开始......");
		int num = 0;
		InstFlowHistory instFlowHistory = beanCopy(instFlowHistoryVO, new InstFlowHistory());
		try {
			num = instFlowHistoryDao.insertInstFlowHistory(instFlowHistory);
			logger.debug("新增数据结束......");
		} catch (Exception e) {
			logger.error("新增数据出现异常!", e);
			num = -1;
		}
		return num;
	}

	@Override
	public List<InstFlowHistoryVO> queryByBizSerno(InstFlowHistoryVO instFlowHistoryVO) {
		logger.debug("根据流程实例编号"+ instFlowHistoryVO +"查询历史审批信息开始......");
		InstFlowHistory instFlowHistory = new InstFlowHistory();
		beanCopy(instFlowHistoryVO,instFlowHistory);
		try {
			List<InstFlowHistory> instFlowHistoryVOS = instFlowHistoryDao.queryByBizSernoByPage(instFlowHistory);
			pageSet(instFlowHistoryVOS,instFlowHistory);
			List<InstFlowHistoryVO> list = (List<InstFlowHistoryVO>) beansCopy(instFlowHistoryVOS, InstFlowHistoryVO.class);
			logger.debug("根据流程实例编号"+ instFlowHistory +"查询历史审批信息开始......");
			return list;
		} catch (Exception e) {
			logger.error("根据流程实例编号"+ instFlowHistory +"查询流程信息出现异常!", e);
		}
		return null;

	}

	@Override
	public int update(InstFlowHistoryVO instFlowHistoryVO) {
		logger.debug("修改数据开始......");
		int num = 0;
		InstFlowHistory instFlowHistory = beanCopy(instFlowHistoryVO, new InstFlowHistory());
		try {
			num = instFlowHistoryDao.update(instFlowHistory);
			logger.debug("修改数据结束......");
		} catch (Exception e) {
			logger.error("修改数据出现异常!", e);
			num = -1;
		}
		return num;
	}

	@Override
	public int deleteByBizSerno(String bizSerno) {
		logger.debug("删除数据开始......");
		int num = 0;
		try {
			num = instFlowHistoryDao.deleteByBizSerno(bizSerno);
			logger.debug("删除数据结束......");
		} catch (Exception e) {
			logger.error("删除数据出现异常!", e);
			num = -1;
		}
		return num;
	}
}
